import * as types from '../actionTypes'
export default (state = { todoList: [] }, action) => {
  if(action === undefined)return state
  switch (action.type) {
    case types.ADDTOOL:
      state.todoList.push({ 'text': action.text, 'id': Date.now() })
      return JSON.parse(JSON.stringify(state))
    case types.REMOVETODO:
      let index  = state.todoList.filter((item,index)=>{
        if(item.id === action.id){
          return index
        }
      })
      state.todoList.splice(index,1)
    default:
      return state
  }
}